<?
	$javascript->link('scriptaculous/lib/prototype', false);
	$javascript->link('scriptaculous/src/scriptaculous', false);

	if (!isset($paging)) {
		$paging = false;
	}

	if ($paging) {
		?><div class="paging">
			<?php echo $paginator->prev('<<');?>
			<?php echo $paginator->numbers();?>
			<?php echo $paginator->next('>>');?>
		</div><?
	}

?>	<table class="purchases">
		<tr>
			<th></th>
			<th>Date</th>
			<th>Description</th>
			<th>Category</th>
			<th><?= $Settings['currency_symbol'] ?></th>
			<th></th>
			<?
			if (isset($fieldName)) {
				?><th width="15%">Re-assign category</th><?
			}
			?>
		</tr>
	<?

	$i = 0;
	foreach($purchases as $p) {
		$class = null;
		if ($i++ % 2 == 0) {
			$class = ' class="altrow"';
		}
		$id = $p['Purchase']['id'];
		?>
		<tr<?php echo $class;?>>
			<td id="star<?= $id ?>" class="star"><?
				echo $this->renderElement('star', array('starred'=>$p['Purchase']['starred'], 'id'=>$id));
			?></td>
			<td class="date"><?= $time->format('d/m/Y', $p['Purchase']['date']) ?></td>
			<td class="description">
			<?= $html->link($p['Purchase']['description'], array('controller'=>'purchases', 'action'=>'edit', $id)) ?>
			<div class="to"><?= $p['Purchase']['to'] ?></div>
			</td>
			<td class="category"><?= $html->link($p['Category']['name'], array('controller'=>'categories', 'action'=>'view', $p['Category']['id'])) ?></td>
			<td class="amount"><?= $number->format($p['Purchase']['amount'], 2) ?></td>
			<td>
			<?= $html->link('Delete', array('controller'=>'purchases', 'action'=>'delete', $id)) ?>
			</td>
			<?
			if (isset($fieldName)) {
				?><td class="checkbox"><?
					?>
					<input type="checkbox" name="data[Purchase][id][]" value="<?= $id ?>" />
					<?
				?></td><?
			}
			?>
		</tr><?
	}
	?>
	</table>
	<?
		if ($paging) {
		?><div class="paging">
			<?php echo $paginator->prev('<<');?>
			<?php echo $paginator->numbers();?>
			<?php echo $paginator->next('>>');?>
		</div><?
	}
	?>

